﻿using System;
using System.Linq;
using System.Windows;
using Caliburn.Micro;

namespace PocketBook.Model
{
    public abstract class Design : PropertyChangedBase, IDesign
    {
        private readonly ILayoutMetrics _metrics;

        protected Design()
        {
            _metrics = IoC.Get<ILayoutMetrics>();

            var resourceAttribute = (DesignResourcesAttribute) GetType()
                .GetCustomAttributes(typeof (DesignResourcesAttribute), false)
                .FirstOrDefault();

            if (resourceAttribute == null) return;

            var info = resourceAttribute.FindResource<string>(this).Split('|');

            DisplayName = info[0];
            Description = info[1];
        }

        public bool IsCustomisable
        {
            get;
            protected set;
        }

        public Size Size
        {
            get { return _metrics.SiteSize; }
        }

        public string DisplayName
        {
            get; set;
        }

        public string Description
        {
            get; set;
        }

        public virtual object Clone()
        {
            var design = (Design) Activator.CreateInstance(GetType());
            design.DisplayName = DisplayName;

            return design;
        }
    }
}